package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2022/1/9 11:58
 * @description：https://leetcode-cn.com/problems/slowest-key/
 */
public class 按键持续时间最长的键 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.slowestKey(new int[]{9,29,49,50}, "cbcd"));
    }

    class Solution {
        public char slowestKey(int[] releaseTimes, String keysPressed) {
            int maxTime = releaseTimes[0];
            char maxChar = keysPressed.charAt(0);
            for (int i = 1; i < keysPressed.length(); i++) {
                char c = keysPressed.charAt(i);
                int curTime = releaseTimes[i] - releaseTimes[i - 1];
                if (curTime >= maxTime && (curTime > maxTime || c > maxChar)) {
                    maxChar = c;
                    maxTime = curTime;
                }
            }
            return maxChar;
        }
    }
}
